#include <bits/stdc++.h>

#define int long long

using namespace std;

const int N = 2e5 + 10;

struct tp
{
    int z, x, y;
};
int pre[N];

void create(int i)
{
    pre[i] = i;
}

signed main()
{
    auto findx = [&](auto &&self, int x)
    {
        if (pre[x] == x)
            return x;
        return pre[x] = self(self, pre[x]);
    };
    auto merge = [&](int x, int y)
    {
        pre[findx(findx, y)] = findx(findx, x);
    };
    int n, m;
    cin >> n >> m;
    vector<tp> arr;
    for (int i = 1; i <= n; i++)
    {
        create(i);
    }

    arr.push_back({0, 0, 0});
    for (int i = 1; i <= m; i++)
    {
        int z, x, y;
        cin >> z >> x >> y;
        arr.push_back({z, x, y});
    }

    for (int i = 1; i <= m; i++)
    {
        if (arr[i].z == 1)
        {
            merge(arr[i].x, arr[i].y);
        }
        else
        {
            if (findx(findx, arr[i].x) == findx(findx, arr[i].y))
            {
                cout << "Y" << endl;
            }
            else
            {
                cout << "N" << endl;
            }
        }
    }
    return 0;
}